$NG.AllReady(function (page, { useAction, useBeforeClick, useValuesChange, useClick, useUpdateRow, subscribe, useUpdateRows }) {
    const mstform = $NG.getCmpApi("baseInfo")
    const dgrid1 = $NG.getCmpApi("")
    const getHeadValue = (str) => mstform.getItem(str).getValue()
    try {
        const toolbar = $NG.getCmpApi("CntMToolbar")
        console.log(`便跟给、`,toolbar);
        window._catch_listbtn = setInterval(()=>{
            if(!toolbar.getItem("updateCntStatus")){
                toolbar.insert({
            id: "updateCntStatus",
            text: "更新合同状态",
            iconCls: "icon-New"
        });
            }
        },1000)
        toolbar.insert({
            id: "updateCntStatus",
            text: "更新合同状态",
            iconCls: "icon-New"
        });

        useClick(() => {
            $NG.external.showDrawer({
                title: '变更合同状态',
                content: $NG.createElement('Form', {
                    id: 'drawer_form',
                    colspan: 1,
                    config: [
                        {
                            xtype: 'select',   // 或者 'select'，看你们框架里怎么定义
                            label: '合同状态',
                            name: 'status',
                            options: [
                                { value: '01', label: '执行中' },
                                { value: '02', label: '已完成' },
                                { value: '03', label: '未执行' }
                            ]
                        }
                    ]
                }),
                onOk() {
                    const form = $NG.getCmpApi('drawer_form');
                    console.log('form的值', form.getValues());
                    const data = form.getValues()
                    if($NG.getCmpApi("grid").getSelectedData().length !== 1){
                        $NG.alert("请选中一行！")
                        return false
                    }
                    const phid = $NG.getCmpApi("grid").getSelectedData()[0].PhId
                    $NG.execServer("UPDATE",{tableName:"pcm3_cnt_m",valueSql:`user_htzt = '${data.status}'`,filterSql:`phid = '${phid}'`},(res)=>{
                        $NG.message(res.msg)
                        
                    })
                }
            });
        }, "updateCntStatus")
    } catch (e) {
        clearInterval(window._catch_listbtn)
        console.log(`列表页代码段报错，非列表页可以无视`,);
    }
    //init 
    
    try{
        hiddenKeys()
    }catch(e){
        console.error(`e`,e);
    }

    useValuesChange(() => {
        hiddenKeys()
    }, "user_sfjcpt")

    useValuesChange(()=>{
        getSupplyInfo()
    },"user_gysmc")


    // 隐藏字段
    function hiddenKeys() {
        let hidden = false
        const user_sfjcpt = mstform.getItem("user_sfjcpt").getValue()
        if (user_sfjcpt == '01') {
            hidden = false
        } else {
            hidden = true
        }
        mstform.getItem("user_jcptcgbh").setProps({
            hidden
        })
    }

    // 获取供应商信息
    function getSupplyInfo(){
        const phid = mstform.getItem("user_gysmc").getValue()
        if(!phid) return 
        $NG.execServer("getSupplyInfo",{phid},(res)=>{
            if(res.count == 0) return 
            const data = JSON.parse(res.data)[0].extendObjects
            const arr = [
                {
                    key:'user_nsrsbh',
                    value:data.unisocialcredit
                },
                {
                    key:'user_khh',
                    value:data.taxbank_name
                },
                {
                    key:'user_zh',
                    value:data.taxaccountno
                },
                {
                    key:'user_dz',
                    value:data.taxaddress
                },
                {
                    key:'user_dh',
                    value:data.taxtelephone
                },
                {
                    key:'user_lxr',
                    value:data.taxpayername
                },
                {
                    key:'user_sx',
                    value:data.user_sx
                },{
                    key:'user_hh',
                    value:{
                        label:data.taxbank_no,
                        value:data.taxbank_id
                    }
                }
            ]
            setHeadValue(arr)
        })
    }

    // 赋值
    function setHeadValue(datas){
        datas.forEach(item=>{
            try{
                mstform.getItem(item.key).setValue(item.value)
            }catch(err){
                console.log(`err`,err,item);
            }
        })
    }
})